tmap xfun::pkg_attach(c("tidyverse", "sf", "geobr", "censobr", "tmap"))
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
##
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
##
## Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
## remotes::install_github('r-tmap/tmap')
Obtemos dados domiciliares do Censo IBGE. Lembrando que o dicionário
dos dados pode ser consultado com data_dictionary().
# data_dictionary(2010, 'households')
domestico_br <- read_households(year = 2010, add_labels = 'pt', showProgress = FALSE)
Precisamos do mapa do Brasil segundo a divisão territorial dos municípios.
municipios_br <- geobr::read_municipality(year = 2010, showProgress = FALSE) |>
mutate(code_muni = as.character(code_muni))
Como mostrar os dados de acesso à internet através do computador,
no estado do Rio grande do sul, com mapas interativos? Usamos a
função tmap_mode("view") e adicionamos mapas base com
tm_basemap(). Vejamos o exemplo:
tmap_mode("view")
## tmap mode set to interactive viewing
domestico_br |>
collect() |>
group_by(code_muni) |>
count(acesso_internet = V0220, wt = V0010) |>
mutate(proporcao = n / sum(n) * 100) |>
collect() |>
left_join(y = filter(municipios_br, code_state == 43), by = "code_muni") |>
st_sf() |>
drop_na() |>
tm_shape() +
tm_basemap(c(StreetMap = "OpenStreetMap", TopoMap = "OpenTopoMap")) +
tmap_options(check.and.fix = TRUE) +
tm_fill("proporcao", alpha = .7, palette = '-Spectral',
id = "name_muni",
title = "Acesso à Internet\npor Computador (%)") +
tm_facets(by = "acesso_internet")
Este é apenas um exemplo simples. Outras opções de customização são possíveis. Não obstante, podemos considerar qualquer outro tipo de dado que possa ser mapeado ou unido com o mapa base.
Wickham, H., Çetinkaya-Rundel, M., & Grolemund, G. (2023). R for data science (2e): import, tidy, transform, visualize, and model data. “O’Reilly Media, Inc.”. Disponível em: https://r4ds.hadley.nz/
Edzer Pebesma, (2018). Simple Features for R: Standardized Support for Spatial Vector Data. The R Journal 10:1, 439-446.
Pebesma, E.; Bivand, R. (2023). Spatial Data Science: With Applications in R (1st ed.). 314 pages. Chapman and Hall/CRC.
Pereira, R.H.M.; Gonçalves, C.N.; et. all (2019) geobr: Loads Shapefiles of Official Spatial Data Sets of Brazil. GitHub repository - https://github.com/ipeaGIT/geobr.
Pereira, Rafael H. M.; Barbosa, Rogério J. (2023) censobr: Download Data from Brazil’s Population Census. R package version v0.2.0, https://CRAN.R-project.org/package=censobr.
Tennekes, M., (2018), tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39.